using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace MyPwdGenerator
{
    public partial class PwdGeneratorForm : Form
    {
        public PwdGeneratorForm()
        {
            InitializeComponent();
        }

        private void lengthNumericUpDown_ValueChanged(object sender, EventArgs e)
        {

        }

        private void generateButton_Click(object sender, EventArgs e)
        {
            pwdTextBox.Text = Generate((int)lengthNumericUpDown.Value);
        }

        private void closeButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void PwdGeneratorForm_Load(object sender, EventArgs e)
        {
        }

        public string Generate(int length)
        {
            // uses linear congruential generator to create a different password for 
            // every day of the year. Can easily enhance to generate a different password 

            // for every day indpendent of year but will have to chose new paramaters. (32, 7, 62) 
            string utcMonth = DateTime.UtcNow.ToString("MM");
            string utcDay = DateTime.UtcNow.ToString("dd");
            string utcSec = DateTime.UtcNow.ToString("ss");
            string utcFSec = DateTime.UtcNow.ToString("ffff");
            int dVal = Int32.Parse(utcDay.ToString());
            int mVal = Int32.Parse(utcMonth.ToString());
            int sVal = Int32.Parse(utcSec.ToString());
            int fVal = Int32.Parse(utcFSec.ToString());

            string charSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            string pwd = "";

            int[] randomList = new int[length];
                        
            randomList[0] = dVal + mVal;
            
            for (int i = 1; i < length; i++)
            {
                randomList[i] = (32 * randomList[i - 1] + 7) % 62;
                pwd += charSet[randomList[i]];
            }

            return pwd;
        }

        private void nextButton_Click(object sender, EventArgs e)
        {
            pwdTextBox.Text = Generate((int)lengthNumericUpDown.Value);
        
        }
    }
}